import api from "../../../../../common/api"
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    cityCode: {
      type: String,
      value: '',
    },
  },
    /* 组件的生命周期*/
  lifetimes: {
    attached: function () {
      getApp().globalData.loginPromise.then(() => {
        this.checkSubmitOpenCity()
      });
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    open: true
  },

  /**
   * 组件的方法列表
   */
  methods: {
    applyOpening() {
      this.doRequestOpenCity()
      .then(()=>{
        this.setData({
        open: false
      })
    })
     
    },
    // 联系客服
    onTMK() {
      return new Promise((resolve, reject) => {
        api.getPrivateSale({}, res => {
          wx.makePhoneCall({
            phoneNumber: res.data.content.serviceMobile,
            success() {},
            fail() {}
          })
        })
      })
    },

    // 申请开通
    doRequestOpenCity(){
      return new Promise((resolve, reject) => {
        api.doRequestOpenCity({
          activityCode: 'OWNER_HO_ACTIVITY', //活动code
          activityCode2: this.data.cityCode //城市code
        }, (res) => {
          if (res && res.data && res.data.isSuccess) {
            resolve()
          } else {
            reject()
          }
        })
      })
    },
    //检查是否提交过城市开通
    checkSubmitOpenCity(){
      return new Promise((resolve, reject) => {
        api.checkSubmitOpenCity({
          activityCode: 'OWNER_HO_ACTIVITY', //活动code
          activityCode2: this.data.cityCode //城市code
        }, (res) => {
          if (res && res.data && res.data.isSuccess) {
            if(res.data.content){
              this.setData({
                open: false
              })
            }
            resolve()
          } else {
            reject()
          }
        })
      })
    }
  }
})